﻿Public Class AppScheduler
    '_queue = []
    Private m_Queue As Queue(Of TimeDef)

    Public Sub New()
        m_Queue = New Queue(Of TimeDef)
    End Sub
    Public ReadOnly Property Count() As Integer
        Get
            Return m_Queue.Count
        End Get
    End Property
    ''' <summary>
    ''' Add new time definition to the queue.
    ''' </summary>
    Public Sub Push(ByVal tdef As TimeDef)
        m_Queue.Enqueue(tdef)
    End Sub
    ''' <summary>
    ''' Reduces the time left to execute a process.
    ''' If time left is zero, process is removed from the queue.
    ''' </summary>
    ''' <returns>TimeDef object whose time is reduced</returns>
    Public Function Tick() As TimeDef
        If m_Queue.Count = 0 Then
            Return Nothing
        End If

        Dim curDef As TimeDef = m_Queue.Peek
        curDef.Tick()
        If curDef.TimeLeft <= 0 Then
            m_Queue.Dequeue()
        End If
        Return curDef
    End Function

    Public Function GetEnumerator() As IEnumerator(Of TimeDef)
        Return m_Queue.GetEnumerator
    End Function

End Class
